﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Workbench.Core;
using SharedGenomics.Domain;
using SharedGenomics.Annotations;

namespace SharedGenomics.Workbench.Presenters
{
    public class TextMinedPublicationsAnnotationMenuProvider : AnnotationMenuProvider
    {
        public TextMinedPublicationsAnnotationMenuProvider(CommandFactory commandFactory, IMenuFactory menuFactory)
            : base(commandFactory, menuFactory)
        {
        }

        public override IMenuItem CreateMenu(IAnnotation annotation)
        {
            PublicationsAnnotation pubAnnotation = (PublicationsAnnotation)annotation;
            IList<Publication> publications = pubAnnotation.Publications;

            if(publications.Count == 0)
                return null;

            IMenuItem menu = this.MenuFactory.CreateContextMenuItem();
            menu.DisplayText = String.Format("Publications ({0})", publications.Count);
            menu.Command = this.CommandFactory.CreateOpenPresenterAnnotationCommand<TextMinedPublicationsPresenter>(FormDisplayMode.NonModalDialog, p => p.Annotation = pubAnnotation, pubAnnotation);

            return menu;
        }

        public override Type AnnotationType
        {
            get { return typeof(PublicationsAnnotation); }
        }
    }
}
